package com.gaeig.base;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;

public class ApplicationInjector {
  private static Injector injector;

  public static Injector getInjector() {
    return injector;
  }

  public static void init(String moduleName) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    String[] moduleNames = moduleName.split(",");
    Module[] modules = new Module[moduleNames.length];
    int index = 0;
    for (String aModuleName : moduleNames) {
      Module module = (Module) Class.forName(aModuleName).newInstance();
      modules[index++] = module;
    }
    injector = Guice.createInjector(modules);
  }
}
